package doublepointer;

/**
 * @Classname : TwoSumIIInputArrayIsSorted
 * @Description : <a href="https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/">167. 两数之和 II - 输入有序数组</a>
 * @Author : chentianyu
 * @Date 2023/2/23 23:48
 */


public class TwoSumIIInputArrayIsSorted {
    public int[] twoSum(int[] numbers, int target) {
        int l = 0, r = numbers.length - 1;
        while (l < r) {
            int sum = numbers[l] + numbers[r];
            if (sum == target) return new int[]{l+1, r+1};
            else if (sum > target) r--;
            else l++;
        }
        return new int[2];
    }
}
